package com.mz.ozy.adapter;

import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.bean.SortBean;
import com.mz.ozy.utils.glideUtils.GlideUtils;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * Created by Administrator on 2018/11/20.
 */

public class ScheduledAdapter extends BaseQuickAdapter<SortBean.ClassBListBean, BaseViewHolder> {

    public ScheduledAdapter(@Nullable List<SortBean.ClassBListBean> data) {
        super(R.layout.item_hot_door_sort, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final SortBean.ClassBListBean item) {
        helper.addOnClickListener(R.id.iv_minus)
                .addOnClickListener(R.id.iv_add)
                .addOnClickListener(R.id.rl_select)
                .addOnClickListener(R.id.rl_item_view);

        TextView tvTitle = helper.getView(R.id.tv_title);
        ImageView ivIcon = helper.getView(R.id.iv_icon);
        TextView tvInfo = helper.getView(R.id.tv_info);
        TextView tvMoney = helper.getView(R.id.tv_money);
        TextView tvGoodsCount = helper.getView(R.id.tv_goods_count);

        String imgPath = "";
        if (!TextUtils.isEmpty(item.getImg_zt())) {
            final String[] imgarr = item.getImg_zt().split(",");
            if (imgarr.length > 0) {
                imgPath = imgarr[0];
            }
        }
        if (!imgPath.equals(ivIcon.getTag())) {
            ivIcon.setTag(imgPath);
            GlideUtils.loadRoundImg(mContext, ivIcon, imgPath, R.mipmap.default_foods_icon, 4);
        }

        tvMoney.setText(getPrice(item));
        tvGoodsCount.setText(String.valueOf(item.getNum()));
        tvTitle.setText(item.getTradename());
        tvInfo.setText(item.getWeight());
    }

    @NotNull
    private String getPrice(SortBean.ClassBListBean item) {
        String price = "";
        if (!TextUtils.isEmpty(item.getPrice()) && Double.parseDouble(item.getPrice()) != 0.00) {
            price += "¥";
            price += item.getPrice();
        }
        if (!TextUtils.isEmpty(item.getMarket_price()) && Double.parseDouble(item.getMarket_price()) != 0.00) {
            if (!TextUtils.isEmpty(price)) {
                price += "+";
                price += item.getMarket_price();
                price += "积分";
            } else {
                price += item.getMarket_price();
                price += "积分";
            }
        }
        if (TextUtils.isEmpty(price)) {
            price = "¥0.00";
        }
        return price;
    }
}
